//
//  RootRightViewController.m
//  片刻
//
//  Created by lanou3g on 15/6/2.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootRightViewController.h"
#import "HomeViewController.h"
#import "RadioViewController.h"
#import "MainListBaseViewController.h"

@interface RootRightViewController ()

@property (nonatomic,retain) UIButton *changeFramebutton;//可以改变frame的Button
@property (nonatomic,retain) MainListBaseViewController *rootVC; //公共的试图控制器

@end

@implementation RootRightViewController
-(void)dealloc
{
    self.changeFramebutton = nil;
    self.rootVC = nil;
     [super dealloc];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    [self createButton];
    self.view.backgroundColor = [UIColor greenColor];
    self.rootVC = [[HomeViewController alloc] init];
    [self.view addSubview:self.rootVC.view];
    self.rootVC.rootRightVC = self;
    
}

//创建一个button的方法
//-(void)createButton
//{
//    self.changeFramebutton = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    _changeFramebutton.frame = CGRectMake(10, 50, 50, 50);
//    [_changeFramebutton addTarget:self action:@selector(handleChangeframeButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
//    _changeFramebutton.backgroundColor = [UIColor yellowColor];
//    [self.view addSubview:_changeFramebutton];
//}

//    点击 设置偏移量 的方法
-(void)handleChangeframeButtonAction
{
    CGRect nawFrame = self.view.frame;
    if (nawFrame.origin.x == 0) {
        nawFrame.origin.x = 270; //如果origin 是0的话就偏移270
    }
    else{
        nawFrame.origin.x = 0;  //否则就回来
    }
    self.view.frame = nawFrame;
}

//根据传进来的下标决定添加什么样的试图
-(void)addViewWith:(ClassNameModel *)index
{
    if ([self.rootVC isMemberOfClass:NSClassFromString(index.className)]) {
        
    }
    else{
        [self.rootVC.view removeFromSuperview]; //移除之前的试图
        NSString *className = index.className;
        self.rootVC = [[NSClassFromString(className) alloc] init];
        UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:self.rootVC];
        navi.navigationBar.hidden = YES;
        
        [self.view addSubview:navi.view];
        self.rootVC.rootRightVC = self; //赋值
        [self.rootVC release];
    }
    [self handleChangeframeButtonAction];
  
}

////根据传过来的下标决定移除哪儿一个试图
//-(void)removeViewWith:(NSInteger)index
//{
////    if (index == 0) {
////        [self.homeVC.view removeFromSuperview];
////    }
////    else{
////        [self.radioVC.view removeFromSuperview];
////    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
















